package com.lijy.awt.border;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.border.Border;

public class BorderFrame extends JFrame {
    private static final int WIDTH = 600;
    private static final int HEIGHT = 300;
    private JPanel demoPanel;
    private JPanel buttonPanel;
    private ButtonGroup group;

    public BorderFrame() {
        setSize(WIDTH, HEIGHT);
        demoPanel = new JPanel();
        buttonPanel = new JPanel();
        group = new ButtonGroup();

        addRadioButton("Lowered bevel", BorderFactory.createLoweredBevelBorder());
        addRadioButton("Raised bevel", BorderFactory.createRaisedBevelBorder());
        addRadioButton("Etched", BorderFactory.createEtchedBorder());
        addRadioButton("line", BorderFactory.createLineBorder(Color.blue));
        addRadioButton("Matte", BorderFactory.createMatteBorder(10,10,10,10,Color.blue));
        addRadioButton("Empty", BorderFactory.createEmptyBorder());

        Border etched = BorderFactory.createEtchedBorder();
        Border titled = BorderFactory.createTitledBorder(etched, "Border types");
        buttonPanel.setBorder(titled);

        setLayout(new GridLayout(2, 1));
        add(demoPanel);
        add(buttonPanel);
//        pack();
    }

    public void addRadioButton(String buttonName, final Border b) {
        JRadioButton button = new JRadioButton(buttonName);
        button.addActionListener(
                new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        demoPanel.setBorder(b);
                    }
                }
        );
        group.add(button);
        buttonPanel.add(button);
    }

    public static void main(String[] args) {
        EventQueue.invokeLater(
                new Runnable() {
                    public void run() {
                        JFrame frame = new BorderFrame();
                        frame.setTitle("BorderTest");
                        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                        frame.setVisible(true);
                    }
                }
        );
    }
}
